<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="org.limp.mine.StringTool"%>
<%@ page import="org.limp.mine.RandomUtil"%>
<%@ page import="org.limp.mine.DateTrimmer"%>
<%@ page import="jt.classic.system.ISystem"%>
<%@ page import="jt.classic.system.user.IUser"%>
<%@ page import="jt.classic.app.info.AInfoDirectory"%>
<%
	String context = jt.classic.system.ISystem.getContextPath();

	IUser user = ISystem.getSessionUser(request);

	AInfoDirectory adirec = (AInfoDirectory) request
			.getAttribute("adirec");

	String title = adirec.isroot() ? "专题" : "栏目";
	
	String key = RandomUtil.getRandomString(5, false);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>新建<%=title%></title>
</head>
<jsp:include page="../head.jsp"></jsp:include>
<script>
   function handleFile(thizz,tp){
      var type = thizz.value.lastIndexOf(".") > 0 ? thizz.value.substring(thizz.value.lastIndexOf(".") + 1,thizz.value.length):"";
      tp.value = type;
   }

   function handleSubmit(){
      if(isblank(document.form1.idname)){
         alert("请定义<%=title%>名称");
      }else{ 
             if(document.form1.idlabelimg){
	            handleFile(document.form1.idlabelimg,document.form1.idlabelimgtype);
	         }
	         if(document.form1.idtitleimg){
	            handleFile(document.form1.idtitleimg,document.form1.idtitleimgtype);
	         }
      
		    Ext.MessageBox.wait('提交保存过程中...');   
		    Ext.Ajax.request({       
		        //请求地址       
		       url: context + "/app/info.do?method=savedirectory",       
		       //提交参数组       
		       fileUpload: true,   
		       form: 'form1',   
		       scope: 'form1',     
		       //成功时回调       
		       success: function(response, options) {       
		           //获取响应的json字符串        
		           Ext.MessageBox.hide();
		           
		           var json = response.responseText;    
                   var o = Ext.util.JSON.decode(json);
		           
		           if (o.success) {
                       Ext.Msg.alert('提示', '提交保存成功！'); 
                       var sub = parent.window;
                       sub.addNode(o.id, o.name, o.iconCls, o.pid);
                   }else{
		               Ext.Msg.alert('提示', '提交保存失败！'); 
		           }                
		       }      
		     });    
     }   
     
   }
</script>
<body>
<form id="form1" name="form1" method="post">
<input type="hidden" name="idparent" value="<%=adirec.id()%>"> <input
	type="hidden" name="iduserid" value="<%=user.id()%>"> <input
	type="hidden" name="idusername" value="<%=user.iname()%>"> <input
	type="hidden" name="iddate" value="<%=DateTrimmer.getYMDHMS()%>">
<input type="hidden" name="idkey" value="<%=adirec.ikey() %>_<%=key %>">	
<div style="width:600px;margin:10px;"><input type="button"
	value="提交保存" onclick="handleSubmit();">
	<input type="reset" value="重新填写"/>
	</div>	
<fieldset id="lanmu" style="width:600px;margin:10px;">
<legend>新建栏目</legend>
<label>上级节点 : </label> 
<%=adirec.iname()%>
<br />
<label for="idname"><%=title%>名称 : </label> 
<input name="idname" id="idname" type="text" tabindex="1" style="width:410px;"/> <font color="red" title="必填项"><b>*</b></font>
<br />
<%
if (adirec.isroot()) {
%>
	<label for="idtemp">显示模板 : </label>
	<input type="text" name="idtemp" id="idtemp"
			value="/template1/index.jsp" style="width:410px;"/>
	<br />
	<label for="idlabelimg">标识图片 : </label>
	<input type="hidden" name="idlabelimgtype" value=""/>
	<input type="file" title="可作为访问专题/栏目的链接标识图片"
			name="idlabelimg" id="idlabelimg" style="width:410px;"/>
	<br />		
	<label for="idtitleimg">标题图片 : </label>
		<input type="hidden" name="idtitleimgtype" value=""/>
		<input type="file" name="idtitleimg" title="可作为专题/栏目页面的标题图片"
			id="idtitleimg" style="width:410px;"/>
<%
}
%>
<label for="idmemo"><%=title%>说明 : </label> 
<textarea name="idmemo" id="idmemo"></textarea>
<br />
</fieldset>
</form>
</body>
</html>
